package com.example.service.admin;

import com.example.entity.Account;
import com.example.entity.Admin;
import com.example.exception.CustomException;
import com.example.mapper.AdminMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 管理员登录
 */

@Service
public class AdminLoginService {
    @Resource
    private AdminMapper adminMapper;

    public Admin login(Account account) {
        String username = account.getUsername();
        Admin admin = adminMapper.selectByUsername(username);
        if (admin == null) {
            throw new CustomException("500", "管理员不存在!");
        }
        String password = account.getPassword();
        if(!admin.getPassword().equals(password)) {
            throw new CustomException("500", "用户名或密码错误!");
        }
        return admin;
    }
}
